<%--
  Created by IntelliJ IDEA.
  User: 14533
  Date: 2021/11/2
  Time: 10:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/amazeui.min.css" />
    <link rel="stylesheet" href="css/admin.css" />
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">请假管理</strong><small></small></div>
    </div>

    <hr>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <c:if test="${emp.position != 0}"> <!-- 老板不需要请假 -->
                        <button type="button" class="am-btn am-btn-default btnAdd"><span class="am-icon-plus"></span>申请请假</button>
                        <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default btnFindNotes" onclick="sendReq(${emp.position}, ${emp.eid})">
                            <span class="am-icon-archive"></span> 请假记录
                        </button>
                    </c:if>

                    <!-- 老板处理 -->
                    <c:if test="${emp.position==0 }">
                        <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default btnFindNoCheck" onclick="atCheck(0,-1,0)">
                            <span class="am-icon-archive"></span> 待审批
                        </button>

                        <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default btnFindCheck" onclick="atCheck(0,-1,1)">
                            <span class="am-icon-archive"></span> 已审批
                        </button>
                    </c:if>
                                                                                        <!-- atCheck(position, did, status) -->
                    <!-- 经理处理 -->
                    <c:if test="${emp.position==1 }">
                        <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default btnFindNoCheck" onclick="atCheck(1,${emp.did},0)">
                            <span class="am-icon-archive"></span> 待审批
                        </button>

                        <button type="button" style="margin-left: 20px;" class="am-btn am-btn-default btnFindCheck" onclick="atCheck(1,${emp.did},1)">
                            <span class="am-icon-archive"></span> 已审批
                        </button>
                    </c:if>


                </div>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-check"><input type="checkbox" id="chkAll"></th>
                        <th class="table-id" style="width:100px;">ID</th>
                        <th class="table-title">申请人</th>
                        <th class="table-title">请假标题</th>
                        <th class="table-type">事由说明</th>
                        <th class="table-dname">请假开始日期</th>
                        <th class="table-role">请假结束日期</th>
                        <th class="table-role">审批状态</th>
                        <c:if test="${emp.position != 2}"><!-- 员工没有操作权限 -->
                            <c:if test="${status == 0}"><!-- 只有待审批的才能操作 -->
                                <th class="table-set">操作</th>
                            </c:if>
                        </c:if>

                    </tr>
                    </thead>
                    <tbody>

                    <c:forEach items="${notes}" var="note">
                        <tr>
                            <td><input type="checkbox" name="chk"></td>
                            <td>${note.nid}</td>
                            <td>${note.realname}</td>
                            <td>${note.title}</td>
                            <td>${note.context}</td>
                            <td class="am-hide-sm-only">
                                <span class="am-badge  am-badge-primary ">
                                    <fmt:formatDate value="${note.startdate}" pattern="yyyy-MM-dd" />
                                </span>
                            </td>

                            <td class="am-hide-sm-only">
                                <span class="am-badge  am-badge-danger ">
                                    <fmt:formatDate value="${note.enddate}" pattern="yyyy-MM-dd" />
                                </span>
                            </td>

                            <td>${note.status==0?'待审核': note.status==1?'同意': note.status==2?"打回":'不同意'}</td>
                            <c:if test="${emp.position != 2}"> <!-- 员工没有操作权限 -->
                                <c:if test="${status == 0}"> <!-- 只有待审批的才能操作 -->
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" id="depart_23" class="am-btn am-btn-default am-btn-xs am-text-secondary btnedit" onclick="updateStatus(${note.nid}, ${emp.position}, ${emp.did}, 1)"><span class="am-icon-pencil-square-o"></span> 同意</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger amt-hide-sm-only" onclick="updateStatus(${note.nid}, ${emp.position}, ${emp.did}, 2)"><span class="am-icon-trash-o"></span> 打回</button>
                                                <button type="button" id="depart_24" class="am-btn am-btn-default am-btn-xs am-text-secondary btnedit" onclick="updateStatus(${note.nid}, ${emp.position}, ${emp.did}, 3)"><span class="am-icon-pencil-square-o"></span> 不同意</button>
                                            </div>
                                        </div>
                                    </td>
                                </c:if>
                            </c:if>

                        </tr>
                    </c:forEach>


                    </tbody>
                </table>
                <div class="am-cf" style="margin-right: 30px;">
                    共 ${lines } 条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <c:if test="${page==1 }">
                                <li class="am-disabled">
                                    <a href="#">«</a>
                                </li>
                            </c:if>
                            <c:if test="${page>1 }">
                                <li>
                                    <c:if test="${position!=2}">
                                        <c:if test="${status != -1}">
                                            <!-- 老板和经理待审批和已审批的下一页 -->
                                            <a href="findNoteByPage?page=${page-1}&size=4&position=${position}&eid=-1&did=${emp.eid}&status=${status}">«</a>
                                        </c:if>
                                    </c:if>
                                    <c:if test="${position!=0}">
                                        <c:if test="${status == -1}">
                                            <!-- 经理和员工的请假记录下一页 -->
                                            <a href="findNoteByPage?page=${page-1}&size=4&position=${position}&eid=${emp.eid}&did=-1&status=-1">«</a>
                                        </c:if>
                                    </c:if>
                                </li>
                            </c:if>

                            <c:forEach begin="1" end="${pages }" step="1" var="index">
                                <c:if test="${index==page }">
                                    <li class="am-active">
                                        <c:if test="${position!=2}">
                                            <c:if test="${status != -1}">
                                                <!-- 老板和经理待审批和已审批的 -->
                                                <a href="findNoteByPage?page=${index}&size=4&position=${position}&eid=-1&did=${emp.eid}&status=${status}">${index}</a>
                                            </c:if>
                                        </c:if>
                                        <c:if test="${position!=0}">
                                            <c:if test="${status == -1}">
                                                <!-- 经理和员工的请假记录下一页 -->
                                                <a href="findNoteByPage?page=${index}&size=4&position=${position}&eid=${emp.eid}&did=-1&status=-1">${index}</a>
                                            </c:if>
                                        </c:if>
                                    </li>
                                </c:if>

                                <c:if test="${index!=page }">
                                    <li>
                                        <c:if test="${position!=2}">
                                            <c:if test="${status != -1}">
                                                <!-- 老板和经理待审批和已审批的 -->
                                                <a href="findNoteByPage?page=${index}&size=4&position=${position}&eid=-1&did=${emp.eid}&status=${status}">${index}</a>
                                            </c:if>
                                        </c:if>
                                        <c:if test="${position!=0}">
                                            <c:if test="${status == -1}">
                                                <!-- 经理和员工的请假记录下一页 -->
                                                <a href="findNoteByPage?page=${index}&size=4&position=${position}&eid=${emp.eid}&did=-1&status=-1">${index}</a>
                                            </c:if>
                                        </c:if>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <c:if test="${page==pages }">
                                <li class="am-disabled">
                                    <a href="#">»</a>
                                </li>
                            </c:if>

                            <c:if test="${page<pages}">
                                <li>
                                    <c:if test="${position!=2}">
                                        <c:if test="${status != -1}">
                                            <!-- 老板和经理待审批和已审批的下一页 -->
                                            <a href="findNoteByPage?page=${page+1}&size=4&position=${position}&eid=-1&did=${emp.eid}&status=${status}">»</a>
                                        </c:if>
                                    </c:if>
                                    <c:if test="${position!=0}">
                                        <c:if test="${status == -1}">
                                            <!-- 经理和员工的请假记录下一页 -->
                                            <a href="findNoteByPage?page=${page+1}&size=4&position=${position}&eid=${emp.eid}&did=-1&status=-1">»</a>
                                        </c:if>
                                    </c:if>
                                </li>
                            </c:if>
                        </ul>
                    </div>
                </div>
                <hr>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="js/jquery-1.11.3.min.js" ></script>
<script type="text/javascript" src="myplugs/js/plugs.js" ></script>
<script>
    $(function() {
        $(".btnAdd").click(function() {
            $.jq_Panel({
                title: "申请请假",
                iframeWidth: 600,
                iframeHeight: 560,
                url: "addLeave.jsp"
            });
        });
    });

    //经理和员工用来查询自己的请假记录
    function sendReq(position, eid) {
        window.location.href="findNoteByPage?page=1&size=4&position=" + position +"&eid=" + eid + "&did=-1&status=-1";
    }

    //老板和经理用来查询待审批和已审批的假条
    function atCheck(position, did, status){
        window.location.href="findNoteByPage?page=1&size=4&position="+position+"&eid=-1&did="+did+"&status=" + status;
    }

    //老板和经理用来处理待审批假条
    //nid：要修改的请假记录ID，position：当前登录用户的职位，did：当前登录用户的部门ID，status：要修改的状态
    function updateStatus(nid, position, did, status) {
        window.location.href="updateStatus?position="+position+"&did="+did+"&status=" + status+"&nid="+nid;
    }

</script>
</body>

</html>